package com.duying.hgk.manager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.duying.gh.GhCommonManager;
import com.duying.hgk.model.PayType;

public class PayTypeManager  extends GhCommonManager{
	public List getSelect(){
		String hql = "from PayType p where p.auditing = 1 and p.parentType is null order by p.sort asc";
		List list = this.baseDao.getByHQL(hql);
		List listSelect = new ArrayList();
		for(int i = 0 ; i < list.size() ; i ++ ){
			PayType p = (PayType)list.get(i);
			Set setType = p.getSetType();
			if(setType == null || setType.isEmpty()){
				Map map = new HashMap();
				map.put("optgroup", 0);
				map.put("value", p.getId());
				map.put("name", p.getType_name());
				listSelect.add(map);
			}else{
				Map map = new HashMap();
				map.put("optgroup", 1);
				map.put("value", p.getId());
				map.put("name", p.getType_name());
				listSelect.add(map);
				Iterator itr = setType.iterator();
				while(itr.hasNext()){
					PayType childP = (PayType)itr.next();
					Map mapchild = new HashMap();
					mapchild.put("optgroup", 0);
					mapchild.put("value", childP.getId());
					mapchild.put("name", "" + childP.getType_name());
					listSelect.add(mapchild);
				}
			}
		}
		return listSelect;
		
	}
	
	
	public List getItemListBy(){
		String hql = "from PayType p where p.auditing = 1 and p.parentType is not null order by p.parentType.sort asc , p.sort asc ";
		return this.baseDao.getByHQL(hql);
	}
}
